package com.niit.TopOne.schooltopone;


import com.niit.bean.StudentBean;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;


public class SchoolGroupingComparator extends WritableComparator {

    protected SchoolGroupingComparator(){
        super(StudentBean.class,true);//允许创建对象实例
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {

        //本需求中 分组规则是，只要前后两个数据的state一样，就应该分到一组
        //只要compare 返回0 mapreduce框架就认为两个一样。返回不为0，就认为不一样
        StudentBean aBean = (StudentBean) a ;
        StudentBean bBean = (StudentBean) b ;


        return aBean.getCity().compareTo( bBean.getCity() );

    }
}
